package com.itheima.article.listener;

import com.itheima.article.service.ApArticleConfigService;
import com.itheima.common.constants.BusinessConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class ArticleUpOrDownListener {

    @Resource
    private ApArticleConfigService apArticleConfigService;

    /**
     * 异步更新文章上架|下架配置
     * @param msg
     */
    @KafkaListener(topics = BusinessConstants.MqConstants.WM_NEWS_DOWN_OR_UP_TOPIC)
    public void articleDownOrUp(ConsumerRecord<String,String> msg){
        int p = msg.partition();
        long o = msg.offset();
        String json = msg.value();
        log.info("异步更新文章上架|下架配置：{},{},{}",p,o,json);
        apArticleConfigService.downOrUp(json);
        log.info("异步更新文章上架|下架配置完成：{},{}",p,o);
    }
}
